package com.example.dryyzx.dao;

import com.example.dryyzx.entity.Bed;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface BedMapper {
    @Delete({
        "delete from bed",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    @Insert({
        "insert into bed (id, bed_number, ",
        "room_number, floor, ",
        "position, bed_status, ",
        "is_occupied)",
        "values (#{id,jdbcType=INTEGER}, #{bedNumber,jdbcType=VARCHAR}, ",
        "#{roomNumber,jdbcType=VARCHAR}, #{floor,jdbcType=VARCHAR}, ",
        "#{position,jdbcType=VARCHAR}, #{bedStatus,jdbcType=VARCHAR}, ",
        "#{isOccupied,jdbcType=BIT})"
    })
    int insert(Bed record);

    @InsertProvider(type=BedSqlProvider.class, method="insertSelective")
    int insertSelective(Bed record);

    @Select({
        "select",
        "id, bed_number, room_number, floor, position, bed_status, is_occupied",
        "from bed",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="bed_number", property="bedNumber", jdbcType=JdbcType.VARCHAR),
        @Result(column="room_number", property="roomNumber", jdbcType=JdbcType.VARCHAR),
        @Result(column="floor", property="floor", jdbcType=JdbcType.VARCHAR),
        @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
        @Result(column="bed_status", property="bedStatus", jdbcType=JdbcType.VARCHAR),
        @Result(column="is_occupied", property="isOccupied", jdbcType=JdbcType.BIT)
    })
    Bed selectByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, bed_number, room_number, floor, position, bed_status, is_occupied",
            "from bed",
            "where bed_number = #{bed_number,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="bed_number", property="bedNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="room_number", property="roomNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="floor", property="floor", jdbcType=JdbcType.VARCHAR),
            @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
            @Result(column="bed_status", property="bedStatus", jdbcType=JdbcType.VARCHAR),
            @Result(column="is_occupied", property="isOccupied", jdbcType=JdbcType.BIT)
    })
    Bed selectByBed_number(@Param("bed_number") String bed_number);

    @Select({
            "select",
            "id, bed_number, room_number, floor, position, bed_status, is_occupied",
            "from bed",
            "where bed_number = #{bed_number,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="bed_number", property="bedNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="room_number", property="roomNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="floor", property="floor", jdbcType=JdbcType.VARCHAR),
            @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
            @Result(column="bed_status", property="bedStatus", jdbcType=JdbcType.VARCHAR),
            @Result(column="is_occupied", property="isOccupied", jdbcType=JdbcType.BIT)
    })
    List<Bed> selectByBedNumber(@Param("bed_number") String bed_number);

    @Select({
            "select",
            "id, bed_number, room_number, floor, position, bed_status, is_occupied",
            "from bed",
            "where room_number = #{room_number,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="bed_number", property="bedNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="room_number", property="roomNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="floor", property="floor", jdbcType=JdbcType.VARCHAR),
            @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
            @Result(column="bed_status", property="bedStatus", jdbcType=JdbcType.VARCHAR),
            @Result(column="is_occupied", property="isOccupied", jdbcType=JdbcType.BIT)
    })
    List<Bed> selectByRoomNumber(@Param("room_number") String room_number);

    @Select({
            "select",
            "id, bed_number, room_number, floor, position, bed_status, is_occupied",
            "from bed",
            "where floor = #{floor,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="bed_number", property="bedNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="room_number", property="roomNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="floor", property="floor", jdbcType=JdbcType.VARCHAR),
            @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
            @Result(column="bed_status", property="bedStatus", jdbcType=JdbcType.VARCHAR),
            @Result(column="is_occupied", property="isOccupied", jdbcType=JdbcType.BIT)
    })
    List<Bed> selectByFloor(@Param("floor") String floor);

    @Select({
            "select",
            "id, bed_number, room_number, floor, position, bed_status, is_occupied",
            "from bed",
            "where position = #{position,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="bed_number", property="bedNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="room_number", property="roomNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="floor", property="floor", jdbcType=JdbcType.VARCHAR),
            @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
            @Result(column="bed_status", property="bedStatus", jdbcType=JdbcType.VARCHAR),
            @Result(column="is_occupied", property="isOccupied", jdbcType=JdbcType.BIT)
    })
    List<Bed> selectByPosition(@Param("position") String position);

    @Select({
            "select",
            "id",
            "from bed",
            "where bed_number = #{bed_number,jdbcType=VARCHAR} and is_occupied = 1"
    })
    int selectBedIdByBedNumber(String bed_number);

    @Select({
            "select",
            "count(*)",
            "from bed",
            "where bed_number = #{bed_number,jdbcType=VARCHAR} and is_occupied = 1"
    })
    int countByBedNumber(String bed_number);

    @Select({
            "select",
            "count(*)",
            "from bed",
            "where room_number = #{room_number,jdbcType=VARCHAR} and is_occupied = 1"
    })
    int countByRoomNumber(String room_number);

    @Select({
            "select",
            "count(*)",
            "from bed",
            "where floor = #{floor,jdbcType=VARCHAR} and is_occupied = 1"
    })
    int countByFloor(String floor);

    @Select({
            "select",
            "count(*)",
            "from bed",
            "where position = #{position,jdbcType=VARCHAR} and is_occupied = 1"
    })
    int countByPosition(String position);

    @Select({
            "select",
            "count(*)",
            "from bed",
            "where floor = #{floor,jdbcType=VARCHAR} and position = #{position,jdbcType=VARCHAR}"
    })
    int countByFloorPosition(@Param("floor")String floor,@Param("position")String position);

    @Select({
            "select",
            "id, bed_number, room_number, floor, position, bed_status, is_occupied",
            "from bed",
            "where floor = #{arg2,jdbcType=VARCHAR} and position = #{arg3,jdbcType=VARCHAR}",
            "limit #{arg0,jdbcType=INTEGER} offset #{arg1,jdbcType=INTEGER}"
    })
    @Results({
            @Result(column="id", property="id", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="bed_number", property="bedNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="room_number", property="roomNumber", jdbcType=JdbcType.VARCHAR),
            @Result(column="floor", property="floor", jdbcType=JdbcType.VARCHAR),
            @Result(column="position", property="position", jdbcType=JdbcType.VARCHAR),
            @Result(column="bed_status", property="bedStatus", jdbcType=JdbcType.VARCHAR),
            @Result(column="is_occupied", property="isOccupied", jdbcType=JdbcType.BIT)
    })
    List<Bed> selectByLimitOffsetFloorPosition(Integer arg0,Integer arg1,String arg2,String arg3);

    @UpdateProvider(type=BedSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Bed record);

    @Update({
        "update bed",
        "set bed_number = #{bedNumber,jdbcType=VARCHAR},",
          "room_number = #{roomNumber,jdbcType=VARCHAR},",
          "floor = #{floor,jdbcType=VARCHAR},",
          "position = #{position,jdbcType=VARCHAR},",
          "bed_status = #{bedStatus,jdbcType=VARCHAR},",
          "is_occupied = #{isOccupied,jdbcType=BIT}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Bed record);
}